//
//  PlatformMy.m
//  reSearchDemo
//
//  Created by 科技 on 15/8/3.
//  Copyright (c) 2015年 Kiwaro. All rights reserved.
//

#import "PlatformMy.h"
#import "PlatformFunctionCell.h"
#import "InformationPlatform.h"
#import "PlatformAuthentication.h"
#import "PlatformWallet.h"

@interface PlatformMy ()<UITableViewDataSource,UITableViewDelegate>
{
    UITableView *_tableView;
    NSMutableArray *_dataSource;
    NSMutableArray *_cellArr;
    BOOL isLoad;                /**< 判断是否push返回 */
}

@property (nonatomic, retain) OnePlatformModel *model;

@end

@implementation PlatformMy

- (id)initWithPlatformModel:(OnePlatformModel *)model {
    self = [super init];
    if (self) {
        self.model = model;
    }
    return self;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if (isLoad) {
        _tableView.frame = CGRectMake(0, 0, self.view.width, self.view.height);
        isLoad = NO;
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"我的";
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame) - 64) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.tableFooterView = [[UIView alloc] init];
    
    [self.view addSubview:_tableView];
    [self loadModel];
}

//加载数据
-(void)loadModel {
    NSArray *textArr = @[@"平台信息",@"平台认证",@"申请商家",@"修改密码",@"平台钱包",@"安全中心",@"常见问题"];
    NSArray *imageArr = @[@"图标1",@"图标2",@"图标3",@"图标4",@"图标5",@"图标6",@"图标7"];
    
    _dataSource = [NSMutableArray array];
    _cellArr = [NSMutableArray array];
    for (int i = 0; i<textArr.count; i++) {
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        [dic setObject:textArr[i] forKey:@"text"];
        [dic setObject:imageArr[i] forKey:@"image"];
        
        [_dataSource addObject:dic];
        
        PlatformFunctionCell *cell = [[PlatformFunctionCell alloc] init];
        [_cellArr addObject:cell];
    }
    
}


#pragma mark --tableViewDelegate--
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataSource.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *indentifier = @"cell";
    PlatformFunctionCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifier];
    if (!cell) {
        cell = [[PlatformFunctionCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentifier];
    }
    
    cell.model = _dataSource[indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    PlatformFunctionCell *cell = _cellArr[indexPath.row];
    cell.model = _dataSource[indexPath.row];
    
    return cell.height;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    switch (indexPath.row) {
        case 0:
        {
            [self pushViewController:[InformationPlatform new]];
            break;
        }
        case 1:
        {
            [self pushViewController:[PlatformAuthentication new]];
            break;
        }
        case 2:
        {
            break;
        }
        case 3:
        {
            break;
        }
        case 4:
        {
            [self pushViewController:[PlatformWallet new]];
            break;
        }
            
            
        default:
            break;
    }
    isLoad = YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
